from deck import Deck
from random import randint
class Player(object):
    def __init__(self, name="", ID=None, score=0.0, wins=0,losses=0,draws=0,achievements=0):
        self.name = name
        # if self.name==None:
        #     self.name="Guest%d"%randint(1,2000)
        
        self.ID = ID
        if self.ID==None:
            self.ID=randint(1,200000000)
        self.score = score
        self.hDeck = Deck("Hazard")
        self.aDeck = Deck("Action")
        self.connection=None
        self.wins=wins
        self.losses=losses
        self.draws=draws
        self.achievements=achievements
    def newGameReset(self):
        self.score = 0
        self.hDeck = Deck("Hazard")
        self.aDeck = Deck("Action")
    def setConnection(self, con):
        self.connection=con

    def __str__(self):
        return self.__repr__()
    def __repr__(self):
        print "Score is:",self.score
        return "Player('%s',%d,%f,%d,%d,%d,%d)"%(self.name, self.ID, self.score,self.wins,self.losses,\
                                                 self.draws,self.achievements)

    def addWins(self):
        self.wins+=1

    def addLosses(self):
        self.losses+=1

    def addDraws(self):
        self.draws+=1

    def showStats(self):
        return "My name is %s (%d) and my score is %f\n\tWins: %d\n\tLosses: %d\n\tDraws: %d\n\tCheevies:%s"%\
               (self.name, self.ID, self.score, self.wins, self.losses, self.draws,repr(self.achievementList()))

    def addAchievement(self,chNum):
        self.achievements=addAchievement(self.achievements,chNum)

    def checkAchievement(self,chNum):
        return checkAchievement(self.achievements,chNum)
    
    def achievementList(self):
        return achievementList(self.achievements)


def addAchievement(mask,chNum):
    return mask | 2**chNum

def checkAchievement(mask,chNum):
    return (mask & 2**chNum)!=0

def achievementList(mask):
    out=[]
    for i in range(10):
        if mask & (2)**(i):
            out.append(i)
    return out




if __name__ == "__main__":
    players = [Player("Mike",8008135),Player("James",1337)]
    players[1].addAchievement(3)
    players[1].addAchievement(9)
    players.append(eval(repr(players[1])))
        
    for i in players:
        print i
        print i.showStats()

#  LocalWords:  chNum addAchievement checkAchievement achievementList
